package com.scy.java.thread;

public class NumBerThread {
    public static void main(String[] args) {
        new Thread("新线程"){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    if (i % 2 != 0) {
                        System.out.print(getName()+"\t"+i+";");
                    }
                }
            }
        }.start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    if (i % 2 == 0) {
                        System.out.print(Thread
                                .currentThread().getName()+"\t"+i+";");
                    }
                }
            }
        }).start();
        //演示线程的优先级，这只当前线程优先级最高
        Thread t = new Thread("许涛涛的线程"){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    if (i % 2 != 0) {
//                        getPriority()获取线程的优先级
                        System.out.print(getName()+"\t"+i+":"+getPriority());
                    }
                }
            }
        };
        //设置当前线程的优先级最高
        t.setPriority(Thread.MAX_PRIORITY);
        //启动线程
        t.start();
        System.out.println(
                Thread.currentThread().getName()
                        +"的优先级"+
                        Thread.currentThread().getPriority());

    }
}
